<template>
  <div class="model-form">
    <el-page-header @back="goBack" content="更新通告">
    </el-page-header>
    <div class="model-content">
      <el-form ref="ruleForm" :rules="rules" :model="form" label-width="160px">
        <el-row :gutter="10">
          <el-col :span="22">
            <el-form-item label="发布人" size="mini" prop="creatorName">
              <el-input v-model="form.creatorName" name="creatorName" disabled>
              </el-input>
            </el-form-item>

          </el-col>
          <el-col :span="22">
            <el-form-item label="单人费用" size="mini" prop="money">
              <el-input v-model="form.money" name="money">
              </el-input>
            </el-form-item>

          </el-col>
          <el-col :span="22">
            <el-form-item label="消费价" size="mini" prop="salePrice">
              <el-input v-model="form.salePrice" name="salePrice">
              </el-input>
            </el-form-item>

          </el-col>
          <el-col :span="22">
            <el-form-item label="招人数" size="mini" prop="amount">
              <el-input v-model="form.amount" name="amount">
              </el-input>
            </el-form-item>

          </el-col>
          <el-col :span="22">
            <el-form-item label="人员性别" size="mini" prop="sex">
              <nb-select catalog="sex" v-model="form.sex"></nb-select>
            </el-form-item>

          </el-col>

          <el-col :span="22">
            <el-form-item label="群二维码" size="mini" prop="qrCode">
              <avatar v-model="form.qrCode"></avatar>
            </el-form-item>

          </el-col>
          <el-col :span="22">
            <div style="margin-left: 160px;">
              <vue-ueditor-wrap v-model="form.note" :config="config" ref="note"></vue-ueditor-wrap>
            </div>
          </el-col>
          <el-col :span="22">
            <el-form-item>
              <el-button @click="goBack">取消</el-button>
              <el-button type="primary" @click="updateData">确定</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
  </div>
</template>

<script>
import nbSelect from "@/components/nbSelect.vue";
import avatar from "@/components/avatar.vue";

import common from "@/mixins/common.js";

export default {
  name: "topic_update",
  mixins: [common],
  components: {
    nbSelect, avatar
  },
  data() {
    return {
      form: {
        creator: '',
        money: '',
        salePrice: '',
        amount: '',
        sex: '',
        note: '',
        qrCode: '',
        topicType: ''
      },
      config : {
        UEDITOR_HOME_URL: '/UEditor/', // 访问 UEditor 静态资源的根路径，可参考常见问题1
        serverUrl: '//model.nbsaas.com/file/ueupload.htm', // 服务端接口（这个地址是我为了方便各位体验文件上传功能搭建的临时接口，请勿在生产环境使用！！！）
        initialFrameWidth: '100%',
        initialFrameHeight: 200,
        toolbars: [[
          'fullscreen', 'source', '|', 'undo', 'redo', '|',
          'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', '|',
          'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
          'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|',
          'directionalityltr', 'directionalityrtl', 'indent'
        ]]
      },
      rules: {
        creator: [
          {required: true, message: '请输入发布人', trigger: 'blur'}
        ],
      }
    }
  },
  async mounted() {
    let id = this.$route.query.id;
    let data = {};
    data.id = id;
    let res = await this.$http.form("/tenantRest/topic/view.htm", data);
    if (res.code === 0) {
      this.form = res;
    }
  },
  methods: {
    async updateData() {
      let res = await this.$refs["ruleForm"].validate();
      if (!res) {
        return;
      }
      await this.updateDataPost();
    },
    async updateDataPost() {
      let res = await this.$http.form("/tenantRest/topic/update.htm", this.form);
      if (res.code !== 0) {
        this.$message.error(res.msg);
        return
      }
      this.$message({
        message: '添加数据成功',
        type: 'success'
      });
      this.$router.go(-1);
    },

  }
}


</script>

<style scoped>

</style>
